
import java.util.Arrays;

public class array {

    public static int[] func3() {
        int[] tmp = new int[]{1,2,3,4};
        return tmp;
    }

    public static void main11(String[] args) {
        int[] rat = func3();
        System.out.println(Arrays.toString(rat));
    }


    public static int[] fib(int n) {
        if(n <= 0) {
            return null;
        }
        int[] array = new int[n];
        array[0] = array[1] = 1;
        for (int i = 2; i < n; i++) {
            array[i] = array[i-1]+array[i-2];
        }
        return array;
    }


    public static void main9(String[] args) {
        int[] array = fib(10);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
    }




    public static void func1(int[] array) {
        array = new int[10];
        //array = {1,2,3,4}; //err
    }
    public static void func2(int[] array) {
        array[0] = 99;
    }




    public static void main8(String[] args) {

        int[] array = {1,2,3,4};
        func1(array);
        func2(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main7(String[] args) {
        int[] array = null;
        System.out.println(array);
        System.out.println(array[0]);
    }

    public static void main6(String[] args) {
        int[] array = {1,2,3,4};
        int[] array2 = {4,5,6,7,8};
        array = array2;
        System.out.println(array);
        System.out.println(array2);
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(array2));

    }

    public static void main5(String[] args) {
        int a = 10;
        int b = 20;
        int[] array = {1,2,3,4};
        System.out.println(array);//打印出一个“地址”
        System.out.println(Arrays.toString(array));
        int[] array2 = array;
        array2[0] = 99;
        System.out.println(Arrays.toString(array));
        System.out.println(Arrays.toString(array2));

    }


    public static void main4(String[] args) {
        //给一个数组赋值1-100
        int[] array = new int[100];
//        for (int i = 1; i < array.length+1; i++) {
//            array[i] = i;
//        }
        for (int i = 0; i < array.length; i++) {
            array[i] = i+1;
        }
        System.out.println(Arrays.toString(array));
    }

    public static void main3(String[] args) {
        //数组遍历
        //法1
        int[] array = {1,2,3};
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] +" ");
        }
        System.out.println();
        //法2
        for (int x : array) {
            System.out.print(x +" ");
        }
        System.out.println();
        //法3
        System.out.println(Arrays.toString(array));


    }
    public static void main2(String[] args) {
        //数组的定义
        int[] array = {1,2,3};
        int[] array1 = new int[]{1,2,3};//如果对数组进行初始化，new后面的括号不用加数组长度
        int[] array3 = new int[10];
        String[] array4 = {"helllo","java"};
        String[] array5 = new String[]{"java","ashda"};
        int[] array6;
//        array6 ={1,2,3}; err
        boolean[] array7 = new boolean[10];
        char[] array8 = new char[10];
        System.out.println("------");
    }

    public static void main1(String[] args) {
        int a = 1;
        int b = 2;
        int c = 3;
        //通过数组，来组织一些数据
        int[] array = {1,2,3};
        float[] array2 = {(float)1.2,(float)1.3,(float)1.4};
        float[] array3 = {1.2f,1.3f,1.4f};
        int ret = array[1];//获取数组数据
        System.out.println(ret);
//        int ret1 = array[3];//获取数组数据 err
//        int ret2 = array[-1];//获取数组数据 err
        int len = array.length;//求数组长度
        System.out.println(len);
    }

}
